<?php

class FortuneAction extends Action{
    
	function _initialize(){
		$this->theme("Bizcard");
	}
	
	function index(){
		$this->display('Fortune/index');
	}
	
	function select() {
		$step = $_GET['step'];
		if($step==0) {
			$step = 1;
		}
		
		if($step==2) {
			$fortune['identity'] = $_GET['identity'];
			session('fortune',$fortune);
		}
		if($step==3) {
			$fortune = session('fortune');
			$fortune['friend'] = $_GET['friend'];
			session('fortune',$fortune);
		}
		if($step==4) {
			$fortune = session('fortune');
			$fortune['share'] = $_GET['share'];
			session('fortune',$fortune);
		}
		if($step==5) {
			$fortune = session('fortune');
			
			//为空跳往首页
			if(empty($fortune)) {
				$this->redirect("/Fortune/index");
			}
			
			$fortune['reuse'] = $_GET['reuse'];
		
			//计算得分
			$score = 0;
			$n = $fortune['friend'];
			$y = $fortune['share']/100;
			$z = $fortune['reuse'];
			if($fortune['identity']==1) {
				$score = ($n*15+$n*300*$y*20+$n*300*$y*300*$y*25)*$z;
			}elseif($fortune['identity']==2) {
				$score = ($n*75+$n*300*$y*60+$n*300*$y*300*$y*40+$n*300*$y*300*$y*300*$y*15)*$z;
			}
			$fortune['score'] = $score; 
			
			
			
			//记录信息
			$db = D('Fortune');
			$data = $fortune;
			$fid = $db->add($data);
			
			
			session('fortune',null);//删除信息
			session('fid',$fid);
			
			//跳往分数显示页面
			$this->redirect("/Fortune/score");
		}
		
		$this->display('Fortune/select_0'.$step);
	}
	
	//得分页面
 	function score() {
 		$db = D('Fortune');
		$map['fid'] = session('fid');
		$result = $db->where($map)->get();
		
		if(empty($result)) {
			$this->redirect("/Fortune/select");
		}
		
 		$this->assign('result',$result);
 		$this->display('Fortune/select_05');
	}
	
	//填写联系方式
	function contact() {
		if($_POST) {
			$map['fid'] = session('fid');
			D('Fortune')->where($map)->save($_POST);
			$this->display('Fortune/success');
			exit();			
		}
		
		$this->display('Fortune/select_06');
	}
	
	
		
	
	

    

    
    
    
    
}